from Liner_Regress.simple import SimpleRegress as LinerRegressModel
from Liner_Regress.ridge import RidgeRegress as RidgeRegressModel
from Liner_Regress.multiply import MutiplyRegress as MutiplyRegressModel

# 线性模型
class LinerModel:
    def __init__(self, denseDegree, remain_dec=2):
        # 数据稠密度
        self.denseDegree = denseDegree
        # 模型：根据数据集数量动态决定是线性回归模型还是岭回归模型
        self.model = None
        # 斜率
        self.slope = 0.0
        # 截距
        self.intercept = 0.0
        # remain_dec模型默认保留小数位数
        self.remain_dec = remain_dec

    # 导入数据集合
    def fit(self, train_x: list[float],train_y: list[float]):
        # 根据数据集稠密度动态选择简单线性回归和岭回归模型实例化
        self.model = LinerRegressModel(remain_dec=self.remain_dec) if len(
            train_x) > self.denseDegree else RidgeRegressModel(_lambda=1.2, remain_dec=self.remain_dec)
        # 添加训练集数据
        self.model.fit(train_x,train_y)
        # 生成斜率
        self.slope = self.model.slope
        # 生成截距
        self.intercept = self.model.intercept

    # 绘制线性图谱
    def drawDataGraph(self, title="semi-liner-regress", xlabel="X-lable", ylabel="Value", color="SeaGreen"):
        self.model.drawDataGraph(title, xlabel, ylabel, color)

    # 预测数据结果
    def predict(self, x: float):
        return self.model.predict(x)
